package com.cityfood.service.impl;

import java.util.List;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cityfood.mapper.CfCityMapper;
import com.cityfood.pojo.CfCity;
import com.cityfood.pojo.CfCityExample;
import com.cityfood.pojo.CfCityExample.Criteria;
import com.cityfood.service.CityService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

@Service
public class CityServiceImpl implements CityService {

	@Autowired
	private CfCityMapper cityMapper;
	
	@Override
	public List<CfCity> getCityLikeCityName(String cityName) {
		CfCityExample cityExample = new CfCityExample();
		Criteria criteria = cityExample.createCriteria();
		criteria.andCityNameLike("%"+cityName+"%");
		//criteria.andIsdisplayEqualTo((byte)1);
		List<CfCity> list = cityMapper.selectByExample(cityExample);
		return list;
	}
	
	@Override
	public PageInfo<CfCity> getCityLikeCityNamePage(String cityName,Integer pageNum) {
		//设置分页的页数和行数
		PageHelper.startPage(pageNum, 20);
		
		CfCityExample cityExample = new CfCityExample();
		Criteria criteria = cityExample.createCriteria();
		criteria.andCityNameLike("%"+cityName+"%");
		//criteria.andIsdisplayEqualTo((byte)1);
		List<CfCity> list = cityMapper.selectByExample(cityExample);
		
		//5.获取分页信息
		PageInfo<CfCity> info = new PageInfo<>(list);
		return info;
	}

	@Override
	public CfCity getCityByCityId(Integer cityId) {
		CfCity city = cityMapper.selectByPrimaryKey(cityId);
		return city;
	}

	@Override
	public int insertCity(CfCity city) {
		int i = cityMapper.insertSelective(city);
		return i;
	}

	@Override
	public int updateCity(CfCity city) {
		int i = cityMapper.updateByPrimaryKeySelective(city);
		return i;
	}

	@Override
	public int deleteCity(CfCity city) {
		city.setIsdisplay((byte)0);
		int i = cityMapper.updateByPrimaryKeySelective(city);
		return i;
	}

	@Override
	public List<CfCity> getAllCitys() {
		CfCityExample cityExample = new CfCityExample();
		
		List<CfCity> list = cityMapper.selectByExample(cityExample);
		return list;
	}

}
